package tests;

import static org.junit.Assert.*;

import java.awt.Color;
import java.util.ArrayList;


import org.junit.*;

import ui.Tile;


import functionality.Player;

public class testPlayer{

	
	Player p1,  //Valid Player Initialization
		   p2,  //Invalid LandScape type
		   p3,  //Invalid Player Color 
		   p4,  //Invalid Building type
		   p5;  //Invalid Player Number
	ArrayList<Player> players = new ArrayList<Player>();
	
	/*Initialize players and put them in an ArrayList*/
	@Before
	public void createPlayers(){
		p1 = new Player(Color.blue, "plain", "none", 1); 
		p2 = new Player(Color.red, "sky", "village", 2);
		p3 = new Player(Color.black, "forest", "town", 3);
		p4 = new Player(Color.yellow, "plain", "ufo", 4);
		p5 = new Player(Color.green, "forest", "village", 5);
		

		players.add(p1);
		players.add(p2);
		players.add(p3);
		players.add(p4);
		players.add(p5);
	}
	
	/**
	 * Test Case: Player Constructor Test
	 * Test Data: Initialized Players in an ArrayList. 
	 * 	 		  Player p1 is a valid initialization, p2-p5 are invalid.
	 * 
	 * Expected Results: An initialized player has 30 knights, 2 tiles in their hand, 
	 * 		             and 22 tiles to be added to their hand later.
	 * 
	 * 		BUG!!!	     Currently fails if the land type and building structure are not valid 'A' tiles
	 * 					 because it won't add them to the Player' hands.
	 */
	@Test
	public void testPlayerConstructor(){
		for(int i = 0; i < players.size(); i++){
				assertEquals("Player " + (i+1) + " error ", players.get(i).getNumKnights(), 30);
				assertEquals("Player " + (i+1) + " error ", players.get(i).getNumCards(), 22);
			    assertEquals("Player " + (i+1) + " error ", players.get(i).getNumCardsInHand(), 2);		
		}
	}
	
	/**
	 * Test Case: Test Tiles In Hand
	 * Test Data: Initialized players in an ArrayList. p1 is a valid initialization. The rest are not.
	 * 			  Strings of the Tiles in hand that represent the land type and building structure.
	 * 
	 * Expected Results: All tiles in hand hold valid building structures (as strings) and 
	 * 	                 valid land types (as strings).
	 */	
	@Test
	public void testGetAllTilesInHand(){	
		/*Test that land type is either a plain, mountain, lake, or forest for all Tiles in hand*/	
		for(int i = 0; i < p1.getNumCardsInHand(); i++){
			String tmp = p1.getTileInHand(i).getLandScape();
			if(!tmp.equalsIgnoreCase("plain") && !tmp.equalsIgnoreCase("mountain") && !tmp.equalsIgnoreCase("forest"))
				assertEquals("Tile is " + tmp, tmp, "lake");
			else if(!tmp.equalsIgnoreCase("lake") && !tmp.equalsIgnoreCase("mountain") && !tmp.equalsIgnoreCase("forest"))
				assertEquals(tmp, "plain");
			else if(!tmp.equalsIgnoreCase("plain") && !tmp.equalsIgnoreCase("lake") && !tmp.equalsIgnoreCase("forest"))
				assertEquals(tmp, "mountain");
			else if(!tmp.equalsIgnoreCase("plain") && !tmp.equalsIgnoreCase("mountain") && !tmp.equalsIgnoreCase("lake"))
				assertEquals(tmp, "forest");
			else
				fail("The tile was not a lake, plain, mountain, or forest!");
		}
		
		/*Test that the building type is either a castle, village, town, or none*/
		for(int i = 0; i < p1.getNumCardsInHand(); i++){
			String tmp = p1.getTileInHand(i).getBuildingStructure();
			if(!tmp.equalsIgnoreCase("castle") && !tmp.equalsIgnoreCase("village") && !tmp.equalsIgnoreCase("town"))
				assertEquals(tmp, "none");
			else if(!tmp.equalsIgnoreCase("none") && !tmp.equalsIgnoreCase("village") && !tmp.equalsIgnoreCase("town"))
				assertEquals(tmp, "castle");
			else if(!tmp.equalsIgnoreCase("castle") && !tmp.equalsIgnoreCase("none") && !tmp.equalsIgnoreCase("town"))
				assertEquals(tmp, "village");
			else if(!tmp.equalsIgnoreCase("castle") && !tmp.equalsIgnoreCase("village") && !tmp.equalsIgnoreCase("none"))
				assertEquals(tmp, "town");
			else
				fail("The tile was not a castle, village, town, or none");
		}		
	}//end testGetAllTilesInHand()
	
	
	/**
	 * Test Case: Test Tiles In Player Stack
	 * Test Data: An ArrayList of Tiles to represent a hand. This hand is longer than a normal two tile 
	 *            hand so that multiple removes can be called for testing.
	 * 
	 * Expected Results: All tiles in the stack hold valid building structures 
	 *  				 (as strings) and valid land types (as strings).
	 */	
	@Test
	public void testRemoveTileInHand(){
	
		
		
	}	
}

